package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.FollowListEntity;
import com.sgb.knowledgeshare.view.fragment.ShareMinFansListFragment;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by fq on 2020/9/11 0011
 * Description：分享-我-关注和粉丝列表
 */
public class ShareMinFansListModel extends ViewModel {

    ShareMinFansListFragment fragment;
    public void setActivity(ShareMinFansListFragment shareMinFansListFragment) {
        fragment = shareMinFansListFragment;
    }

//    关注
    public void getFollowList(int page, String userid) {
        Map map = new HashMap();
        map.put("pageNum",page);
        map.put("pageSize",20);
        map.put("userNo",userid);
        DialogHelper.showProgressDialog(fragment.getContext(), null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getFollowList(map).enqueue(new ICallBack<BaseEntity<FollowListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<FollowListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    fragment.setFollowList(data.getData());
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });

    }

//    粉丝
    public void getFensList(int pageSize, String userid) {
        Map map = new HashMap();
        map.put("pageNum",pageSize);
        map.put("pageSize",20);
        map.put("userNo",userid);
        DialogHelper.showProgressDialog(fragment.getContext(), null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getFensList(map).enqueue(new ICallBack<BaseEntity<FollowListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<FollowListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    fragment.setFensList(data.getData());
                } else {

                }
            }
        });
    }

//    关注、取消关注
    public void getFens(String userNo) {
        Map map = new HashMap();
        map.put("userNo",userNo );
        ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    fragment.setFens();
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }


}
